package main

import "fmt"

type Node struct {
	value int
	left ,right *Node
}

//先序遍历
func PreorderTraversal(root *Node) {
	if root != nil {
		fmt.Print(root.value)
		PreorderTraversal(root.left)
		PreorderTraversal(root.right)
	}
}

//中序遍历
func InorderTraversal(root *Node) {
	if root != nil {
		InorderTraversal(root.left)
		fmt.Print(root.value)
		InorderTraversal(root.right)
	}
}

//后续遍历
func PostorderTraversal(root *Node) {
	if root != nil {
		PostorderTraversal(root.left)
		PostorderTraversal(root.right)
		fmt.Print(root.value)
	}
}

func main() {
	root := &Node{value:0}
	root.left = &Node{value: 1}
	root.right = &Node{value: 2}
	root.left.right = &Node{value: 3}
	root.right.right =&Node{value: 4}

	fmt.Print("先序遍历:")
	PostorderTraversal(root)
	fmt.Println()

	fmt.Print("中序遍历:")
	InorderTraversal(root)
	fmt.Println()

	fmt.Print("后序遍历:")
	PostorderTraversal(root)
	fmt.Println()

}
